<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Configuration Handler
 *
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category    Configuration 
 * @package     Config
 * @author      Kazuyoshi Tlacaelel <kazu.php@gmail.com> 
 * @copyright   2007 Kazuyoshi Tlacaelel
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version     SVN: $Rev: 69 $
 */

/**
 * API Configuration Handler
 *
 * This Configuration Handler provides an interface that can be called 
 * statically from anywhere thus improving accessability.
 *
 * Aiming to provide a configuration's manipulation-tool 
 * without defining data or parameters. In this way configuration files
 * can be created, merged, altered and replaced.
 * independetly of the configuration's manipulating-implementation itself.
 *
 * for instance if the application is moved to a different envirionment
 *
 * <code>
 *
 * // define a sample id
 * $id = 'my.setting'; 
 *
 * // adding configuration data
 * config::set($id, ' Hello World ! '); 
 *
 * // checking if a configuratin is defined
 * if (config::exists($id)) {
 *
 *     // retriving configuration data 
 *     echo config::get($id); 
 *
 * } 
 *
 * // exporting configuration 
 * var_export(config::export()); 
 * 
 * // will output something like 
 *
 *      //
 *      // array (
 *      //     'my.setting' => ' Hello World ! ',
 *      // )
 *      //
 *
 * // removing configuration data
 * config::remove($id); 
 * 
 * // exporting an empty configuration
 * var_export(config::export());
 *
 * // will output something like
 *      //
 *      // array ()
 *      //
 *
 * </code>
 *
 * Making configuration files
 *
 * <code> 
 *
 * // file mysql.config.php 
 * config::set('mysql.user');
 * config::set('mysql.pass');
 * config::set('mysql.host');
 * config::set('mysql.port');
 *
 *
 * // file ftp.config.php 
 * config::set('ftp.user');
 * config::set('ftp.pass');
 * config::set('ftp.host');
 * config::set('ftp.port');
 *
 * // merging
 * require_once 'mysql.config.php';
 * require_once 'ftp.config.php';
 *
 * </code> 
 *
 * @package       
 * @copyright   1997-2005 The PHP Group
 * @author      Kazuyoshi Tlacaelel <ktlacaelel@gmail.com> 
 * @license     PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
 */
class Config
{
    protected 

    /**
     * configuration data 
     *
     * Holds all the configuration parameters and their values
     * 
     * @static
     * @access  protected 
     * @var     array
     * @access  public
     */
    static $data = array();

    /**
     * configuration getter
     * 
     * @param   string  $id     the identifier string for a setting
     * @static
     * @access  public
     * @return  mixed 
     */
    public static function get($id)
    {
        if (self::exists($id)) return self::$data[$id];
    }

    /**
     * configuration setter
     * 
     * sets the value of a new configuration setting idenfied by id
     *
     * @param   string    $id 
     * @param   mixed     $value 
     * @static
     * @access  public
     * @return  void
     */
    public static function set($id, $value)
    {
        self::$data[$id] = $value;
    }

    /**
     * configuration existance checker
     * 
     * scans the current configuration and finds out if a given id was 
     * previously defined
     *
     * @param   string  $id 
     * @static
     * @access  public
     * @return  boolean
     */
    public static function exists($id)
    {
        return array_key_exists($id, self::$data);
    }

    /**
     * configuration remover
     * 
     * scans the current configuration and removes a setting identified by 
     * id
     *
     * @param   string  $id 
     * @static
     * @access  public
     * @return  boolean
     */
    public static function remove($id)
    {
        if (self::exists($id)) {
            unset(self::$data[$id]);
            return true;
        }
        return false;
    }

    /**
     * configuration exporter
     * 
     * returns the current configutation with all of its values
     *
     * @static
     * @access  public
     * @return  void
     */
    public static function export()
    {
        return self::$data;
    }
}

?>
